public class StrStr {

    public static int solution(String haystack, String needle){
        int s1=0;
        int res=-1;
        if(haystack.length()<needle.length()){
            return res;
        }
        for (int i = 0; i < haystack.length(); i++) {
            if(haystack.charAt(i)==needle.charAt(s1)){
                if(res<0){
                    res=i;
                }
                s1++;
                if(s1==needle.length()){
                    return res;
                }
            } else{
                s1=0;
                res=-1;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        String a="mississippi";
        String b="issip";
        System.out.println(solution(a, b));
    }
}
